from ironxl import *
# Load the Excel workbook
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet
# Select a range
selected_range = worksheet["A1:D20"]
# Select a column(B)
column = worksheet.GetColumn(1)
# Sort the range in ascending order (A to Z)
selected_range.SortAscending()
# Sort the range by column(C) in ascending order
selected_range.SortByColumn("C", SortOrder.Ascending)
# Sort the column(B) in descending order (Z to A)
column.SortDescending()
# Save changes with the sorted range and column
workbook.SaveAs("sortExcelRange.xlsx")
C#에서 Excel 범위 정렬하기
데이터를 알파벳 순서 또는 숫자 순서로 정리하면 분석이 실용적이고 효율적입니다. IronXL for Python을 사용하면 엑셀의 열, 행 및 범위를 최소한의 코드로 쉽게 정렬할 수 있습니다.
어떤 선택된 범위나 열에서라도 SortAscending 또는 SortDescending 메서드를 사용하여 원하는 순서로 정렬을 적용하세요. SortByColumn 메서드는 두 개의 매개변수가 필요합니다. 첫 번째는 정렬할 열이고, 두 번째는 정렬 순서입니다.